#define  _CRT_SECURE_NO_WARNINGS  1
#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>

class Solution {
public:
    int triangleNumber(vector<int>& nums) {
        sort(nums.begin(), nums.end());
        int count = 0, n = nums.size();
        for (int i = n - 1; i >= 2; i--)
        {
            int left = 0, right = i - 1;
            while (left < right)
            {
                if (nums[left] + nums[right] > nums[i])
                {
                    count += right - left;
                    right--;
                }
                else
                {
                    left++;
                }
            }
        }
        return count;
    }
};

int main()
{
    vector<int> v = { 4,2,3,4 };
    cout << Solution().triangleNumber(v) << endl;
}